package com.test1.service.impl;

import com.test1.dao.IUserTestMapper;
import com.test1.model.UserTest;
import com.test1.service.ITransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class TransferServiceImpl implements ITransferService {
    @Autowired
    private IUserTestMapper iuid;
    @Override
    public String transfer(int id1, int id2, String money) {
        UserTest user1 = iuid.getUser(id1);
        UserTest user2 = iuid.getUser(id2);

        user1.setUser_money(Integer.parseInt(user1.getUser_money()) - Integer.parseInt(money) + "");
        user2.setUser_money((Integer.parseInt(user2.getUser_money()) + Integer.parseInt(money)) + "");

        int u1 = iuid.updateMoneyById(id1, user1.getUser_money());
        // System.out.println(1/0);
        int u2 = iuid.updateMoneyById(id2, user2.getUser_money());

        return u1 > 0 && u2 > 0 ? "转账成功" : "转账失败";
    }

    @Override
    public List<UserTest> selUser(UserTest ut) {
        return iuid.getUserByAgeAndSchool(ut);
    }

    @Override
    public int setUserInfo(UserTest ut) {
        return iuid.updateUserInfo(ut);
    }

    @Override
    public List<UserTest> getUsersByAge(List<String> ages) {
        return iuid.getUsersByAge(ages);
    }

}
